package fr.pascal.client.ui.selection;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

import fr.pascal.client.ui.MainResources;

public class SelectionRubriquesImpl extends Composite implements SelectionRubriques {

	private static SelectionRubriquesImplUiBinder uiBinder = GWT
			.create(SelectionRubriquesImplUiBinder.class);
	
	MainResources resources = GWT.create(MainResources.class);
	
	@UiField 
	Button bAnimaux;
	
	@UiField
	Button bWwe;

	interface SelectionRubriquesImplUiBinder extends
			UiBinder<Widget, SelectionRubriquesImpl> {
	}

	public SelectionRubriquesImpl() {
		resources.mainStyle().ensureInjected();
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	private Presenter presenter;

	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
	
	@UiHandler("bAnimaux")
	void onAnimauxClick(ClickEvent event) {
		presenter.goTo("2");
	}
	
	@UiHandler("bWwe")
	void onWweClick(ClickEvent event) {
		presenter.goTo("1");
	}

	@Override
	public void setSelectedRubrique(String selectedRubrique) {
		if ("1".equals(selectedRubrique)) {
			bWwe.setStyleName(resources.mainStyle().clickedButton());
			bAnimaux.setStyleName(resources.mainStyle().notClickedButton());
		} else if ("2".equals(selectedRubrique)) {
			bWwe.setStyleName(resources.mainStyle().notClickedButton());
			bAnimaux.setStyleName(resources.mainStyle().clickedButton());
		} 
	}
}
